﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using WFL.Wrapper.Highcharts;

namespace WFL.Demo.WebForm
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ShowPie();
            ShowColumn();
        }

        private void ShowPie()
        {
            HighchartsObject chart = new HighchartsObject();
            chart.Credits = new CreditsObject() { Href = "http://www.baidu.com", Text = "妈妈再也不用担心我饿肚子了" };
            chart.Title = "肉夹馍";
            chart.Tooltip = "{series.name}: <b>{point.percentage:.1f}%</b>";
            PieObject pie = new PieObject();
            pie.AllowPointSelect = true;
            pie.Cursor = "pointer";
            DataLabelsObject labels = new DataLabelsObject();
            labels.Enabled = true;
            labels.Color = "#000000";
            labels.ConnectorColor = "#000000";
            labels.Format = "<b>{point.name}</b>: {point.percentage:.1f} %";
            pie.DataLabels = labels;
            pie.ShowInLegend = true;
            chart.PlotOptions = new PlotOptionsObject() { Pie = pie };
            SeriesObject series = new SeriesObject();
            series.Type = "pie";
            series.Name2 = "独家配方";
            series.Data = new object[] { 
                new object[] { "面粉", 55 },
                new object[] { "水", 5 },
                new object[] { "小辣椒", 10 },
                new object[]{"香菜",5},
                new SeriesDataObject(){Name2="密制炖肉",Y=25,Sliced=true,Selected=true}
            };
            chart.Series = new object[] { series };
            string chartScript = chart.Render("#pieChart");
            ClientScript.RegisterClientScriptBlock(typeof(_Default), "pie", chartScript, true);
        }

        private void ShowColumn()
        {
            HighchartsObject chart = new HighchartsObject();
            chart.Chart = new ChartObject() { Type = "column" };
            chart.Credits = new CreditsObject() { Href = "http://www.baidu.com", Text = "妈妈再也不用担心我饿肚子了" };
            chart.Title = new TitleObject("战斗力指数");
            chart.XAxis = new XAxisObject[] { new XAxisObject() { Categories = new string[] { "周日", "周一", "周二", "周三", "周四", "周五", "周六" } } };
            chart.YAxis = new YAxisObject[] { 
                new YAxisObject() { Min = 0, Title = new TitleObject("战斗力（N）") },
                new YAxisObject() { Min = 0, Title = new TitleObject("利用率（%）"), Opposite=true } 
            };
            chart.Tooltip = new TooltipObject()
            {
                HeaderFormat = "<span style=\"font-size:10px\">{point.key}</span><table>",
                PointFormat = "<tr><td style=\"color:{series.color};padding:0\">{series.name}: </td><td style=\"padding:0\"><b>{point.y:.1f} N</b></td></tr>",
                FooterFormat = "</table>",
                Shared = true,
                UseHTML = true
            };
            chart.PlotOptions = new PlotOptionsObject()
            {
                Column = new ColumnObject()
                {
                    PointPadding = 0.2f,
                    BorderWidth = 0
                }
            };
            chart.Series = new object[]{
                new SeriesObject(){Name2="体力", Data=new object[]{30,40,50,30,60,80,40}},
                new SeriesObject(){Name2="脑力", Data=new object[]{80,50,40,40,70,60,90}},
                new SeriesObject(){Name2="体力", Data=new object[]{30,40,50,30,60,80,40}, Type="spline", YAxis=1},
                new SeriesObject(){Name2="脑力", Data=new object[]{80,50,40,40,70,60,90}, Type="spline", YAxis=1}
            };
            string chartScript = chart.Render("#columnChart");
            ClientScript.RegisterClientScriptBlock(typeof(_Default), "column", chartScript, true);
        }
    }
}